﻿using AnesSystem.Models.Model.Hospital.SC.WJZYY;
using AnesSystem.Services;
using Common;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AnesSystem.ViewModels.Operation.SC.WJZYY
{
    public class HisAnesMethodCtrlViewModel : BaseViewModel<HisAnesMethodCtrlViewModel>
    {
        #region Variables
        private ObservableCollection<SelHisAnesMethodModel> _displayHisAnesMethodList;
        private List<HisAnesMethodModel> _hisAnesMethodList;
        private string _searchStr;
        private SelHisAnesMethodModel _selectAnesMethod=new SelHisAnesMethodModel();




        #endregion


        #region Constructor
        public HisAnesMethodCtrlViewModel()
        {
            _displayHisAnesMethodList = new ObservableCollection<SelHisAnesMethodModel>();
            _hisAnesMethodList = new List<HisAnesMethodModel>();
            InitData();
        }




        #endregion


        #region Properties
        public ObservableCollection<SelHisAnesMethodModel> DisplayHisAnesMethodList
        {
            get
            {
                return _displayHisAnesMethodList;
            }

            set
            {
                _displayHisAnesMethodList = value;
            }
        }

        public List<HisAnesMethodModel> HisAnesMethodList
        {
            get
            {
                return _hisAnesMethodList;
            }

            set
            {
                _hisAnesMethodList = value;
            }
        }

        public string SearchStr
        {
            get
            {
                if (_searchStr == null)
                {
                    return "";
                }
                return _searchStr;
            }

            set
            {
                _searchStr = value;
                ChangeDispaly();
            }
        }
       
    
        public SelHisAnesMethodModel SelectAnesMethod
        {
            get
            {
                return _selectAnesMethod;
            }

            set
            {
                _selectAnesMethod = value;
                ChangeSelect();
            }
        }

        public void ChangeSelect()
        {
            if (SelectAnesMethod == null)
            {
                foreach (var item in DisplayHisAnesMethodList)
                {
                    item.IsChecked = false;
                }
            }
            else
            {
                foreach (var item in DisplayHisAnesMethodList)
                {
                    string name = item.HisAnesMethodModel.Name;
                    if (!string.IsNullOrEmpty(name))
                    {
                        if (name.Equals(SelectAnesMethod.HisAnesMethodModel.Name))
                        {
                            item.IsChecked = true;
                        }
                        else
                        {
                            item.IsChecked = false;
                        }
                    }
                }

            }
        }

        private void ChangeDispaly()
        {
            DisplayHisAnesMethodList.Clear();

            foreach (var item in HisAnesMethodList)
            {
                string name = item.Name;
                if (name.IsContain(SearchStr))
                {
                    SelHisAnesMethodModel selHisAnesMethodModel = new SelHisAnesMethodModel();
                    selHisAnesMethodModel.HisAnesMethodModel = item;
                    DisplayHisAnesMethodList.Add(selHisAnesMethodModel);
                }
            }
        }

        #endregion


        #region 依赖属性


        #endregion


        #region Event


        #endregion


        #region PrivateMethods
        private void InitData()
        {
            HisAnesMethodList = HisAnesMethodService.Instance.FindAll().ToList();
            foreach (var item in HisAnesMethodList)
            {
                SelHisAnesMethodModel selHisAnesMethodModel = new SelHisAnesMethodModel();
                selHisAnesMethodModel.HisAnesMethodModel = item;
                //if (DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Mzff.Equals(selHisAnesMethodModel.HisAnesMethodModel.Name))
                //{
                //    selHisAnesMethodModel.IsChecked = true;
                //}

                DisplayHisAnesMethodList.Add(selHisAnesMethodModel);
            }
        }

        #endregion


        #region Public/ProtectedMethods


        #endregion


        #region EventHandlers


        #endregion
    }
}
